package top.jnaw.jee.utils;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.codec.digest.DigestUtils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;


public class EnDeCode {

  public static String enCodeMd5(String incode) {
    return DigestUtils.md5Hex(incode);
  }

  public static String enCodeBase64(String incode) {
    BASE64Encoder encoder = new BASE64Encoder();
    byte[] codes = incode.getBytes();
    return encoder.encode(codes);
  }

  public static String deCodeBase64(String decode) {
    BASE64Decoder decoder = new BASE64Decoder();
    String incode = null;
    try {
      byte[] codes = decoder.decodeBuffer(decode);
      incode = new String(codes, StandardCharsets.UTF_8);
    } catch (IOException e) {
    }
    return incode;
  }

}
